#!/bin/sh
a=1
DEVICE='00:25:47:09:95:67'
echo "Proximity Detector"
while [ $a -gt 0 ]
do
	num=$(hcitool con |grep $DEVICE -c) #Filtering $DEVICE from the Active connections and counting the lines returned
	if [ $num -ne 1 ]; then #If the connection is not established
		hcitool cc $DEVICE sed 's/Scanning/d' #then Create a Connection to that device
	elif [ $num == 1 ]; then #If a connection exists to that device, checking again incase the connection dies out.
		hcitool rssi $DEVICE #then return the signal rssi strength
		sleep 2.5s
	fi
	a=`expr $a + 1`
done
